package cn.edu.sgu.www.mhxysy.controller.potency;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.potency.PotencyFruitDTO;
import cn.edu.sgu.www.mhxysy.dto.potency.PotencyFruitMoveDTO;
import cn.edu.sgu.www.mhxysy.entity.potency.PotencyFruit;
import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.potency.PotencyFruitService;
import cn.edu.sgu.www.mhxysy.vo.potency.PotencyFruitPropertyVO;
import cn.edu.sgu.www.mhxysy.vo.potency.PotencyFruitVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "潜能果管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/potency_fruit", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class PotencyFruitController {

    private final PotencyFruitService potencyFruitService;

    @Autowired
    public PotencyFruitController(PotencyFruitService potencyFruitService) {
        this.potencyFruitService = potencyFruitService;
    }

    @ApiOperation("移动潜能果")
    @RequestMapping(value = "/move", method = RequestMethod.POST)
    public JsonResult<Void> move(@Validated PotencyFruitMoveDTO potencyFruitMoveDTO) {
        potencyFruitService.move(potencyFruitMoveDTO);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("返还潜能果经验")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orignId", value = "移动的潜能果ID", required = true),
            @ApiImplicitParam(name = "targetId", value = "目标潜能果ID", required = true)
    })
    @RequestMapping(value = "/return", method = RequestMethod.POST)
    public JsonResult<Void> returnFruit(
            @ApiParam(name = "fruitId", value = "潜能果ID", required = true)
            @NotNull(message = "潜能果" + CustomMessages.ID_NOT_NULL) Integer fruitId) {
        potencyFruitService.returnFruit(fruitId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("更换潜能果属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orignId", value = "移动的潜能果ID", required = true),
            @ApiImplicitParam(name = "targetId", value = "目标潜能果ID", required = true)
    })
    @RequestMapping(value = "/renewal", method = RequestMethod.POST)
    public JsonResult<Void> renewal(
            @NotNull(message = "潜能果" + CustomMessages.ID_NOT_NULL) Integer fruitId,
            @NotNull(message = "属性" + CustomMessages.ID_NOT_NULL) Integer propertyId) {
        potencyFruitService.renewal(fruitId, propertyId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("兑换潜能果")
    @RequestMapping(value = "/exchange", method = RequestMethod.POST)
    public JsonResult<Void> exchange(
            @ApiParam(name = "roleId", value = "角色ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId) {
        potencyFruitService.exchange(roleId);

        return JsonResult.success(CustomMessages.OPERATE_SUCCESS);
    }

    @ApiOperation("添加潜能果")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated PotencyFruitDTO potencyFruitDTO) {
        potencyFruitService.insert(potencyFruitDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除潜能果")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "潜能果ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        potencyFruitService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改潜能果")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated PotencyFruitDTO potencyFruitDTO) {
        potencyFruitService.updateById(potencyFruitDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询兑换下一个潜能果的经验")
    @RequestMapping(value = "/selectExchangeExp", method = RequestMethod.GET)
    public JsonResult<Integer> selectExchangeExp(
            @ApiParam(name = "roleId", value = "角色ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId) {
        Integer exp = potencyFruitService.selectExchangeExp(roleId);

        return JsonResult.success(null, exp);
    }

    @ApiOperation("通过ID查询潜能果详情")
    @RequestMapping(value = "/selectDetail", method = RequestMethod.GET)
    public JsonResult<PotencyFruitVO> selectDetail(
            @ApiParam(name = "id", value = "潜能果ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        PotencyFruitVO potencyFruitVO = potencyFruitService.selectDetail(id);

        return JsonResult.success(null, potencyFruitVO);
    }

    @ApiOperation("分页查询潜能果列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<PotencyFruit>> selectByPage(Pager<PotencyFruit> pager) {
        Page<PotencyFruit> page = potencyFruitService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

    @ApiOperation("查询潜能果列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", required = true),
            @ApiImplicitParam(name = "schemaId", value = "潜能果方案ID", required = true)
    })
    @RequestMapping(value = "/selectList", method = RequestMethod.GET)
    public JsonResult<List<PotencyFruit>> selectList(
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId,
            @NotNull(message = "潜能果方案" + CustomMessages.ID_NOT_NULL) Integer schemaId) {
        List<PotencyFruit> list = potencyFruitService.selectList(roleId, schemaId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("查询潜能果详情列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "roleId", value = "角色ID", required = true),
            @ApiImplicitParam(name = "schemaId", value = "潜能果方案ID", required = true)
    })
    @RequestMapping(value = "/selectDetails", method = RequestMethod.GET)
    public JsonResult<List<PotencyFruitVO>> selectDetails(
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId,
            @NotNull(message = "潜能果方案" + CustomMessages.ID_NOT_NULL) Integer schemaId) {
        List<PotencyFruitVO> list = potencyFruitService.selectDetails(roleId, schemaId);

        return JsonResult.success(null, list);
    }

    @ApiOperation("通过角色ID查询潜能果加成属性")
    @RequestMapping(value = "/selectAdditiveProperties", method = RequestMethod.GET)
    public JsonResult<List<PotencyFruitPropertyVO>> selectAdditiveProperties(
            @ApiParam(name = "roleId", value = "角色ID", required = true)
            @NotBlank(message = CustomMessages.ROLE_ID_NOT_NULL) String roleId) {
        List<PotencyFruitPropertyVO> list = potencyFruitService.selectAdditiveProperties(roleId);

        return JsonResult.success(null, list);
    }

}